// pages/mine/minebangfu/dongTai.js
var app = getApp();
import Api from '../../../api/api.js';
const api = new Api();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageIndex: 1,
    pageCount: 10,
    dataList: [],
    basesId:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.basesId = options.basesId;
    this.getListData();
  },
  getListData() {
    var _this = this;
    var map = {};
    map.baseId = this.data.basesId;
    map.pageCount = this.data.pageCount;
    map.pageIndex = this.data.pageIndex;
    api.getRequestData(app.jiDiDongTaiListUrl, map, true, "POST").then(res => {
      if (res.data.errorCode == 0) {
        var list = res.data.model.list;
        console.log("=====",JSON.stringify(list));
        if (list.length == 0) {
          app.alert("没有更多数据了～");
        }
        if (_this.data.pageIndex == 1) {
          _this.data.dataList = list;
          _this.setData({
            dataList: _this.data.dataList
          });
        } else {
          // 加载更多
          _this.setData({
            dataList: _this.data.dataList.concat(list)
          });
        }
      } else {
        wx.showToast({
          title: res.data.errorMsg,
          icon: 'none',
          duration: 1500
        });
      }
    });
  },
  updatePerViewimage(e) {
    var _this = this;
    var index = e.currentTarget.dataset.key + "";
    var arr = index.split("_");
    var indexA = parseInt(arr[0] + "");
    var indexB = parseInt(arr[1] + "");
    var array = this.data.dataList;
    var dic = array[indexA];
    var imageList = dic.assistUpdateImgs;
    var currentUrlItem = imageList[indexB];
    var currentUrl = currentUrlItem.img;
    var list = [];
    for (var i = 0; i < imageList.length; i++) {
      var item = imageList[i];
      list.push(item.img);
    }
    wx.previewImage({
      current: currentUrl,
      urls: list,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  onPullDownRefresh: function () {
    this.data.pageIndex = 1;
    this.getListData();

  },
  onReachBottom: function () {
    this.data.pageIndex += 1;
    this.getListData();
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})